﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.IO;
using System.Security.Cryptography;

namespace Ebiz.libs
{
    public enum CryptMode { ENCRYPT, DECRYPT }
    public class CryptLib
    {
        public static string Base64(string InputText, CryptMode Mode){
            string result = "";
            switch (Mode) {
                case CryptMode.ENCRYPT:
                    result = EncryptBase64(InputText);
                    break;
                case CryptMode.DECRYPT:
                    result = DecryptBase64(InputText);
                    break;
            }
            return result;
        }

        private static string EncryptBase64(string InputText) {
            byte[] TxtBytes = Encoding.UTF8.GetBytes(InputText);
            string EncryptText = Convert.ToBase64String(TxtBytes);
            return EncryptText;
        }

        private static string DecryptBase64(string InputText) {
            byte[] TxtByteData = Convert.FromBase64String(InputText);
            string SrcText = Encoding.UTF8.GetString(TxtByteData);
            return SrcText;
        }
    }
}
